import instance from '../utils/request';
// 定义基础URL，与后端接口地址对应
const baseURL = "http://172.20.10.10:3000/";
export interface addFormInlineTS {
  username:string,
    phone:string,
    password:string,
    id:string,
    department:string,
    employeestype:string
}
export interface LoginResponse {
  token?: string;
  message?: string;
  data?: any;
}
// 获取所有用户
export const getAllUsers = () => {
  return instance.get(`http://172.20.10.10:3000/user`);
};
// 登录接口
export const Login = async (data: { phone: string; password: string }): Promise<LoginResponse> => {
  // 检查phone和password是否为空
  if (!data.phone || !data.password) {
      throw new Error('手机号和密码不能为空');
  }
  const response = await instance.post(`http://172.20.10.10:3000/user`, data);
  console.log('登录接口完整返回数据结构:', response);
  console.log('登录接口返回数据:', response.data);
  return response.data;
}
// 根据token拿数据
export const getUser = (token:any) => {
  return instance.get(`http://172.20.10.10:3000/user`,{
    headers: {
      Authorization: `Bearer ${token}`, // 携带 Token
    },
  });
};
